package com.yungee.config;

import com.yungee.config.resolver.CommonsMultipartResolverExt;
import com.yungee.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.PathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author wangyun
 * @date 2021/11/11 13:06
 */
@Configuration
@Slf4j
public class UploadConfig {
    @Value("${spring.servlet.multipart.location:}")
    private String uploadFilePath;
    @Bean
    public CommonsMultipartResolverExt commonsMultipartResolver() throws IOException {
        CommonsMultipartResolverExt commonsMultipartResolverExt = new CommonsMultipartResolverExt();
        commonsMultipartResolverExt.setDefaultEncoding("UTF-8");
        commonsMultipartResolverExt.setMaxUploadSize(2000000000L);
        Resource resource = new PathResource(uploadFilePath);
        commonsMultipartResolverExt.setUploadTempDir(resource);
        return commonsMultipartResolverExt;
    }
}
